package com.example.testgit.mapstruct;

import com.example.testgit.VO.AwardVO;
import com.example.testgit.entity.AwardDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author: lyh
 * @create: 2023/5/8 19:50
 * Description：
 */
@Mapper
public interface AwardConverter {
    AwardConverter INSTANCE = Mappers.getMapper(AwardConverter.class);

    @Mappings({
            @Mapping(source = "awardType", target = "awardType", qualifiedByName = "typeTrans"),
            @Mapping(source = "awardLevel", target = "awardLevel", qualifiedByName = "levelTrans"),
            @Mapping(source = "acquireTime", target = "acquireTime", dateFormat = "yyyy-MM-dd")
    })
    AwardVO toVO(AwardDO awardDO);

    @Mappings({
            @Mapping(source = "awardType", target = "awardType", qualifiedByName = "typeTrans"),
            @Mapping(source = "awardLevel", target = "awardLevel", qualifiedByName = "levelTrans"),
            @Mapping(source = "acquireTime", target = "acquireTime", dateFormat = "yyyy-MM-dd")
    })
    List<AwardVO> toVOList(List<AwardDO> awardDOList);

    @Named("typeTrans")
    default String typeTrans(Integer awardType) {
        if (awardType.equals(0)) return "奖学金";
        else if (awardType.equals(1)) return "竞赛";
        else return "助学金";
    }

    @Named("levelTrans")
    default String levelTrans(Integer awardLevel) {
        if (awardLevel.equals(0)) return "国家级";
        else if (awardLevel.equals(1)) return "省级";
        else if (awardLevel.equals(2)) return "校级";
        else if (awardLevel.equals(3)) return "院级";
        else return "公司级";
    }
}
